package com.kdd.campus.sh.dao;
import com.kdd.campus.sh.po.ShProduct;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:ShProduct的Dao
 * @Date 2019/6/14 0:12
 *****/
public interface ShProductMapper extends Mapper<ShProduct> {

    @Update("update sh_product set productNum=productNum-#{num} where Id=#{productId} AND productNum>#{num};")
    int subStock(Long productId, Integer num);


    @Select("<script> " +
            "SELECT * FROM sh_product where created >= now()-interval 3 day " +
            "<if test='order!=null'> ORDER BY price ${order} </if>" +
            "</script>")
    List<ShProduct> getNewProduct(String order);
}
